var MemberApp = function(){
	return{
		init:function(){
			MemberApp.toggleMenu();
		},
		bindPhone:function(){
			var url = $("#APP_ROOT_PATH").val() + 'member/bind_phone';
			var phone = $("#phone").val();
			var code = $("#code").val();
			
			if(!mui.util.StringUtil.isPhone(phone)){
				layer.open({
				    content: '手机号码格式不正确',
				    skin: 'msg',
				    time: 2 //2秒后自动关闭
				  });
				return false;
			}
			
			if(code == ""){
				layer.open({
				    content: '短信验证码不正确',
				    skin: 'msg',
				    time: 2 //2秒后自动关闭
				  });
				return false;
			}
			
			mui.util.Ajax.asyncGET(url,{phone:phone,code:code},function(res){
				if(res.ret != undefined && res.ret != 0){
					layer.open({
					    content: res.message,
					    skin: 'msg',
					    time: 2 //2秒后自动关闭
					  });
					return;
				}
				
				if(!res.flag){
					layer.open({
					    content: '手机号码绑定失败',
					    skin: 'msg',
					    time: 2 //2秒后自动关闭
					  });
				}else{
					var redirectUrl = $("#redirectUrl").val();
					if(redirectUrl != undefined && redirectUrl != ""){
						window.location.href = redirectUrl;
					}else{
						window.location.href = $("#APP_ROOT_PATH").val();
					}
				}
			});
		},
		jump:function(status){
			window.location.href = $("#APP_ROOT_PATH").val() + 'order/index?status=' + status;
		},
		toggleMenu:function(){
			//点击商品列表右上的三个小点，弹出下拉框
			$(".top-bar> .dian").click(function(e){
			    e.preventDefault();
			    $(this).next(".down").toggleClass("hide");
			    console.log(this);
			});
		},
		sendSms:function(){
			if($(".code-link").text() != "获取验证码" ){
				return;
			}
					
			var phone = $("#phone").val();
			
			if(!mui.util.StringUtil.isPhone(phone)){
				layer.open({
				    content: '手机号码格式不正确',
				    skin: 'msg',
				    time: 2 //2秒后自动关闭
				  });
				return false;
			}
			
			var url = $("#APP_ROOT_PATH").val() + 'member/send_sms';
			mui.util.Ajax.asyncGET(url,{phone:phone},function(res){
				if(res.ret != undefined && res.ret != 0){
					layer.open({
					    content: res.message,
					    skin: 'msg',
					    time: 2 //2秒后自动关闭
					  });
					return;
				}
				
				if(res){
					MemberApp.timer(60,$(".code-link"));
				}
			});
		},
		/**
		 * 倒计时
		 */
		timer:function(intDiff,obj){
			var interValObj;
			$(obj).html('(60 s)');
			interValObj = window.setInterval(function(){
				if(intDiff <=1){
					$(obj).attr("disabled",false); 
					$(obj).html('获取验证码');
					window.clearInterval(interValObj);
					return;
				}
				$(obj).html('( ' + intDiff + ' )');
				intDiff--;
			},1000);
		}
	}
}();